using System.IO;
using System.Net.Mail;
using System.Text;
using System;
using System.Configuration;

namespace Dala.Utilities
{

    public sealed class Emailer
    {
        private Emailer()
        {

        }

        public static bool SendMail(string to, string from, string fromName, string subject, string body)
        {
            SmtpClient smtpClient = new SmtpClient();
            MailMessage message = new MailMessage();

            try
            {
                MailAddress fromAddress = new MailAddress(from, fromName);
                //mail server
                smtpClient.Host = ConfigurationManager.AppSettings[SettingsKey.EmailHost.ToString()];

                //From address will be given as a MailAddress Object
                message.From = fromAddress;

                // To address collection of MailAddress
                message.To.Add(to);

                message.Subject = subject;

                //Body can be Html or text format
                //Specify true if it  is html message
                message.IsBodyHtml = true;

                // Message body content
                message.Body = body;

                //Send SMTP mail
                smtpClient.Send(message);
            }
            catch (SmtpException smtpEx)
            {
                return false;
            }
            catch (Exception ex)
            {
                return false;
            }

            return true;
        }

    }
}